package wrice.esm.compiler.fsm;

import wrice.esm.InvalidStateRuntimeException;
import wrice.esm.State;
import wrice.esm.compiler.fsm.event.*;
import wrice.esm.compiler.Parser;

public class ManuallyGenerated_ParserFSM {

	// factory constructor
	public static GlobalDefinitionState CreateFSM( Parser parser )
	{
		return new ManuallyGenerated_ParserFSM( parser ).GetInitialState();
	}

	// private constructor
	private ManuallyGenerated_ParserFSM( Parser parser )
	{
		action_ = parser;
		currentState_ = GetInitialState();
	}
	
	// initial state
	private GlobalDefinitionState GetInitialState()
	{
		return globalDefinitionState_;
	}

	private Parser action_;
	private State currentState_;
	private GlobalDefinitionState globalDefinitionState_ = new GlobalDefinitionState();
	private GlobalDefinition_ActorState globalDefinition_ActorState_ = new GlobalDefinition_ActorState();
	private GlobalDefinition_InitialStateState globalDefinition_InitialStateState_ = new GlobalDefinition_InitialStateState();
	private GlobalDefinitionVariableValueState globalVariableValueState_ = new GlobalDefinitionVariableValueState();
	private StateDefinitionSetState stateDefinitionsState_ = new StateDefinitionSetState();
	private StateDefinitionState stateDefinitionState_ = new StateDefinitionState();
	private EventSetState eventSetState_ = new EventSetState();
	private EventValueState eventValueState_ = new EventValueState();
	private EndState endState_ = new EndState();

	public class GlobalDefinitionState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}
		public GlobalDefinitionState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentBlock( evt );
			return this;
		}
		public GlobalDefinitionState event( CommentLineEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentLine( evt );
			return this;
		}
		public GlobalDefinition_ActorState event( ActorEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			currentState_ = globalDefinition_ActorState_;
			return globalDefinition_ActorState_;
		}
		public GlobalDefinition_InitialStateState event( InitialStateEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			currentState_ = globalDefinition_InitialStateState_;
			return globalDefinition_InitialStateState_;
		}
		public GlobalDefinitionVariableValueState event( VariableNameEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.readGlobalVariableName(evt);
			currentState_ = globalVariableValueState_;
			return globalVariableValueState_;
		}
		public StateDefinitionSetState event( BlockBeginEvent evt ) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			//action_.ReadStateDefinition();
			currentState_ = stateDefinitionsState_;
			return stateDefinitionsState_;
		}
	}

	public class GlobalDefinition_ActorState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}

		public GlobalDefinitionState event(StringValueEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.readGlobalActor( evt );
			currentState_ = globalDefinitionState_;
			return globalDefinitionState_;
		}
	
	}

	public class GlobalDefinition_InitialStateState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}

		public GlobalDefinitionState event(StringValueEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.readGlobalInitialState( evt );
			currentState_ = globalDefinitionState_;
			return globalDefinitionState_;
		}
	
	}
	
	public class GlobalDefinitionVariableValueState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}

		public GlobalDefinitionState event(StringValueEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.readGlobalVariableValue( evt );
			currentState_ = globalDefinitionState_;
			return globalDefinitionState_;
		}
		
	}
	
	public class StateDefinitionSetState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}

		public EndState event(BlockEndEvent blockEndEvent) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			currentState_ = endState_;
			return endState_;
		}

		public StateDefinitionState event(StateNameEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.readStateName(evt);
			currentState_ = stateDefinitionState_;
			return stateDefinitionState_;
		}

		public StateDefinitionSetState event(CommentLineEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentLine( evt );
			return this;
		}

		public StateDefinitionSetState event(CommentBlockEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentBlock( evt );
			return this;
		}
	}
	
	public class StateDefinitionState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}

		public EventSetState event(BlockBeginEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.beginEventSet(evt);
			currentState_ = eventSetState_;
			return eventSetState_;
		}

		public StateDefinitionSetState event(BlockEmptyEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.emptyEventSet(evt);
			currentState_ = stateDefinitionsState_;
			return stateDefinitionsState_;
		}

		public StateDefinitionState event(CommentLineEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentLine( evt );
			return this;
		}

		public StateDefinitionState event(CommentBlockEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentBlock( evt );
			return this;
		}
	}
	
	public class EventSetState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}

		public EventValueState event(EventNameEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.readEventName(evt);
			currentState_ = eventValueState_;
			return eventValueState_;
		}

		public StateDefinitionSetState event(BlockEndEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.endEventSet(evt);
			currentState_ = stateDefinitionsState_;
			return stateDefinitionsState_;
		}

		public EventSetState event(CommentLineEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentLine( evt );
			return this;
		}

		public EventSetState event(CommentBlockEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentBlock( evt );
			return this;
		}
	}
	public class EventValueState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}

		public EventValueState event(CommentLineEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentLine( evt );
			return this;
		}

		public EventValueState event(CommentBlockEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.skipCommentBlock( evt );
			return this;
		}

		public EventSetState event(StateNameEvent evt) {
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			action_.readEventNextStateAndAction( evt );
			currentState_ = eventSetState_;
			return eventSetState_;
		}

		
	}
	public class EndState implements State
	{
		public boolean isCurrentState() {
			return this == currentState_;
		}
	}
}
